package com.sky.controller.rider;

import com.sky.pojo.Courier;
import com.sky.result.Result;
import com.sky.service.admin.OrderDispatchService;
import com.sky.service.rider.CourierOrderService;
import com.sky.service.rider.CourierService;
import com.sky.vo.CourierTradeOrderDetailVO;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

@Slf4j
@RestController
@RequestMapping("/courier")

public class CourierController {
    @Autowired
    private CourierService courierService;
    @Autowired
    private OrderDispatchService orderDispatchService;
    @Autowired
    private CourierOrderService courierOrderService;

    @GetMapping("/receivingOrder")
    public Result<String> receivingOrder(Long courierId ,String tradeNo ){
      return   courierService.receivingOrder(courierId,tradeNo);
    }
    @ApiOperation("骑手拒单转单")
    @GetMapping("/transferOrderToTaskPool")
    public Result<Courier>transferOrderToTaskPool(Long tradeNo ,Long courierId){
        log.info("骑手拒单转单----{},{}",tradeNo,courierId);
       Courier courier = orderDispatchService.dispatch(null,tradeNo,courierId);
       return Result.success(courier);
    }
    @ApiOperation("返回骑手信息")
    @GetMapping("/findById")
    public Result<Courier>findById(Long id){
      Courier courier =  courierService.findById(id);
      return Result.success(courier);
    }
    @ApiOperation("骑手月度统计")
    @GetMapping("/findCourierMonthTradeOrderInfo")
    public Result<CourierTradeOrderDetailVO> findCourierMonthTradeOrderInfo(String courierId,String date) throws ParseException {
        CourierTradeOrderDetailVO vo =  courierOrderService.findCourierMonthTradeOrderInfo(courierId,date);
        return Result.success(vo);
    }
}
